<template>
  <a-card :bordered="false">
    <div class="card-title">{{ $route.meta.title }} {{dirName}} </div>
    <div class="table-operator">
      <!-- 操作板块 -->
      <a-button
        type="primary"
        @click='goBack'
      >返回</a-button>
    </div>
    <s-table
      ref="table"
      rowKey="id"
      :loading="isLoading"
      :columns="columns"
      :data="loadData"
      :pageSize="15"
    >

      <span slot="status" slot-scope="text">
          <a-tag :color='WorkStatusEnum.valueOf(text).color'>{{WorkStatusEnum.getNameByValue(text)}}</a-tag>
      </span>

    </s-table>
  </a-card>
</template>

<script>
import * as Api from '@/api/book/file'
import { STable } from '@/components'

export default {
  name: 'Index',
  components: {
    STable

  },
  data () {
    return {
      dirName:'',
      // 当前表单元素
      searchForm: this.$form.createForm(this),
      // 查询参数
      queryParam: {},
      // 正在加载
      isLoading: false,
      // 表头
      columns: [
        {
          title: '文件名称',
          dataIndex: 'full_name'
        },
        {
          title: '文件编号',
          dataIndex: 'file_no'
        }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: param => {
        return Api.fileList({ ...param, ...this.queryParam })
          .then(response => response.data.list)
      },
      // 会员等级列表
      gradeList: []
    }
  },
  created () {
    this.queryParam.did = this.$route.query.did
    this.dirName = this.$route.query.name
  },
  methods: {

    // 确认搜索
    handleSearch (e) {
      e.preventDefault()
      this.searchForm.validateFields((error, values) => {
        if (!error) {
          this.queryParam = { ...this.queryParam, ...values }
          this.handleRefresh(true)
        }
      })
    },

    /**
     * 刷新列表
     * @param Boolean bool 强制刷新到第一页
     */
    handleRefresh (bool = false) {
      this.$refs.table.refresh(bool)
    },

    goBack(){
      this.$router.go(-1)
    },
  }
}
</script>

<style lang="less" scoped>
.ant-card-body {
  padding: 22px 29px 25px;
}
</style>
